package com.scau402.system1.repository.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.scau402.system1.domain.dto.WmsStopCheckDTO;
import com.scau402.system1.domain.po.WmsAdjustBoundOrderDetailPO;
import com.scau402.system1.domain.po.WmsAuditOrderPO;
import com.scau402.system1.domain.po.WmsCheckboundJadeDetailPO;
import com.scau402.system1.domain.vo.WmsCheckBoundJadeDetailVO;
import com.scau402.system1.mapper.IWmsCheckboundJadeDetailMapper;
import com.scau402.system1.repository.IWmsCheckJadeDetailRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 盘点单翡翠详情Repository实现类
 * @since 2024/2/3
 */
@Repository
@Slf4j
public class WmsCheckJadeDetailRepositoryImpl implements IWmsCheckJadeDetailRepository {
    @Autowired
    private IWmsCheckboundJadeDetailMapper checkJadeDetailMapper;

    /**
     * 批量插入盘点单翡翠信息
     * @param jadeDetailPOList 盘点单翡翠详情列表
     */
    @Override
    public void saveList(List<WmsCheckboundJadeDetailPO> jadeDetailPOList) {
        checkJadeDetailMapper.saveBatch(jadeDetailPOList);
    }

    /**'
     * 根据翡翠条码和盘点单id更新数据
     * @param jadeDetail 需要被更新的数据
     * @param barcode 翡翠条码
     * @param checkOrderId 盘点单id
     */
    @Override
    public void update(WmsCheckboundJadeDetailPO jadeDetail, String barcode, Long checkOrderId) {
        checkJadeDetailMapper.update(jadeDetail,new QueryWrapper<WmsCheckboundJadeDetailPO>().eq("barcode",barcode).eq("check_order_id",checkOrderId));
    }

    /**
     * 根据翡翠条码和盘点单id获取盘点翡翠详情
     * @param barcode 翡翠条码
     * @param checkOrderId 盘点单id
     * @return
     */
    @Override
    public WmsCheckboundJadeDetailPO findJadeByBarcodeAndOrderId(String barcode, Long checkOrderId) {
        return checkJadeDetailMapper.selectOne(new QueryWrapper<WmsCheckboundJadeDetailPO>().eq("barcode", barcode).eq("check_order_id",checkOrderId));
    }

    /**
     * 根据盘点单id获取翡翠数量信息
     * @param checkOrderId 盘点单id
     * @return
     */
    @Override
    public List<WmsCheckboundJadeDetailPO> findNumListByCheckOrderId(Long checkOrderId) {
        return checkJadeDetailMapper.selectList(
                new QueryWrapper<WmsCheckboundJadeDetailPO>()
                        .select("check_order_id","barcode","total_nums", "count_nums", "warehouse_id", "storage_id")
                        .eq("check_order_id", checkOrderId));
    }

    /**
     * 根据盘点单id获取盘点单信息
     * @param checkOrderId 盘点单id
     * @return
     */
    @Override
    public List<WmsCheckBoundJadeDetailVO> findListByCheckOrderId(Long checkOrderId) {
        return checkJadeDetailMapper.findListByCheckOrderId(checkOrderId);
    }

    /**
     * 记录盘点单结果（结束盘点）
     * @param dto
     */
    @Override
    public void stopCheck(WmsStopCheckDTO dto) {
        checkJadeDetailMapper.saveCheckResultBatch(dto);
    }

}
